package org.bulu.project.web.controller;

import org.bulu.project.common.result.Result;
import org.bulu.project.system.model.entity.DanMu;
import org.bulu.project.system.service.DanMuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/danmu")
public class DanmuController {

    @Autowired
    private DanMuService danmuService;

    @GetMapping("/danmus")
    public Result<List<DanMu>> getDanmus(@RequestParam Long videoId,
                                         String startTime,
                                         String endTime) {
        List<DanMu> list;
        try {
            list = danmuService.getDanmus(videoId, startTime, endTime);
            System.out.println(list);
            // 返回成功
            return Result.success(list);
        } catch (Exception e) {
            // 返回失败
            return Result.failed("查询失败：" + e.getMessage());
        }
    }

    @PostMapping("/danmus")
    public Result<DanMu> addDanmu(@RequestBody DanMu danmu) {
        try {
            danmuService.addDanmu(danmu);
            // 返回成功
            return Result.success(danmu);
        } catch (Exception e) {
            // 返回失败
            return Result.failed("添加失败：" + e.getMessage());
        }
    }
}






